
import serial
from django.shortcuts import HttpResponse


ser = serial.Serial('/dev/ttyUSB0', 115200)


def swing_thread(request):
    if request.method == 'GET':
        ser.write('cd robot_arm'.encode())
        ser.write('\r'.encode())
        ser.write('source swing.sh'.encode())
        ser.write('\n'.encode())
        return HttpResponse('swing done')


def handshake_thread(request):
    if request.method == 'GET':
        ser.write('cd robot_arm'.encode())
        ser.write('\n'.encode())
        ser.write('source handshake.sh'.encode())
        ser.write('\n'.encode())
        return HttpResponse('handshake done')


